import request from '../request'
import type { StudentTaskVO, StudentTaskQueryParams, TaskSubmissionDTO, TaskSubmissionVO } from '@/types/task'
import type { PageResult } from '@/types/api'

export const studentTaskApi = {
  // 分页查询任务列表
  getTaskPage: (params: StudentTaskQueryParams) => {
    return request<PageResult<StudentTaskVO>>({
      url: '/v1/student/tasks/page',
      method: 'get',
      params
    })
  },

  // 获取任务详情
  getTaskDetail: (taskId: number) => {
    return request<StudentTaskVO>({
      url: `/v1/student/tasks/${taskId}`,
      method: 'get'
    })
  },

  // 提交任务
  submit: (taskId: number, data: TaskSubmissionDTO) => {
    return request<void>({
      url: `/v1/student/tasks/${taskId}/submit`,
      method: 'post',
      data
    })
  },

  // 修改提交
  updateSubmission: (taskId: number, data: TaskSubmissionDTO) => {
    return request<void>({
      url: `/v1/student/tasks/${taskId}/submission`,
      method: 'put',
      data
    })
  },

  // 获取提交详情
  getSubmissionDetail: (submissionId: number) => {
    return request<TaskSubmissionVO>({
      url: `/v1/student/tasks/submissions/${submissionId}`,
      method: 'get'
    })
  }
}